package com.douwong.student.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.model.ItemsEntity;

import java.util.List;


/**
 * 问答互动
 * 
 * @author leihuajie
 * 
 */
public class AnswerQuestionExhangeAdapter extends BaseAdapter {


	private final Context mContext;
	private final List<ItemsEntity> mArryResult;

	public AnswerQuestionExhangeAdapter(Context context, List<ItemsEntity> arryResult) {

		mContext = context;
		mArryResult = arryResult;
	}

	@Override
	public int getCount() {
		return mArryResult.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.answer_exchange_item, null);
			holder.answer_type_text = (TextView) convertView
					.findViewById(R.id.answer_type_text);
			holder.file_name_text = (TextView) convertView
					.findViewById(R.id.file_name_text);
			holder.subject_text = (TextView) convertView
					.findViewById(R.id.subject_text);
			holder.create_time_text = (TextView) convertView
					.findViewById(R.id.create_time_text);
			holder.star_count_text = (TextView) convertView
					.findViewById(R.id.star_count_text);
			holder.iv_exchange_star = (ImageView) convertView
					.findViewById(R.id.iv_exchange_star);
			convertView.setTag(holder);

		} else {
			holder = (Holder) convertView.getTag();
		}
		if (mArryResult.size() > 0) {
			String timesStr = mArryResult.get(position).getCreate_time()
					.substring(0, 10);
			holder.file_name_text.setText(mArryResult.get(position).getTopic()+""); // 设置标题
			holder.answer_type_text.setText(getTopicType(mArryResult.get(position).getType()));
			holder.create_time_text.setText(timesStr);


		}
		return convertView;
	}

	class Holder {
		TextView star_count_text, file_name_text, answer_type_text,
				subject_text, create_time_text;
		ImageView iv_exchange_star;
	}
	private String getTopicType(int type){
		if (type==1){
			return "单选题";
		}else if (type==2){
			return "多选题";

		}else if (type==15){
			return "判断题";

		}
		return "";
	}
}
